package com.settlement.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.entity.TbOrder;
import com.settlement.system.model.entity.YzBill;
import com.settlement.system.mapper.YzBillMapper;
import com.settlement.system.model.query.YzBillPageQuery;
import com.settlement.system.service.YzBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 有赞账单表 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2023-10-23
 */
@Service
public class YzBillServiceImpl extends ServiceImpl<YzBillMapper, YzBill> implements YzBillService {

    @Override
    public Page<YzBill> getPage(YzBillPageQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        String tableName = "yz_bill_%s".formatted(queryParams.getBillMonth());
        queryParams.setTableName(tableName);
        if (!StringUtils.hasText(this.baseMapper.existTable(tableName))) {
            return new Page<>(pageNum, pageSize);
        }
        // 查询数据
        Page<YzBill> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

    @Override
    public boolean createTable(String tableName) {
        return this.getBaseMapper().createTable(tableName) > 0;
    }

    @Override
    public List<YzBill> getList(YzBillPageQuery queryParams) {
        return this.baseMapper.getList(queryParams);
    }
}
